package com.my.mybits.mapper;

import com.my.mybits.po.Publisher;
import org.apache.ibatis.annotations.*;

import java.util.List;

public interface PublisherMapper {
    Publisher findPublisherByPubId(int pubId);
    Publisher findPublisherByPubIdEx(Integer pubId);

    List<Publisher> findPublisherByPubNameKey(String namekey);

    @Options(keyColumn="pub_id",keyProperty="pubId",useGeneratedKeys=true)
    @Insert("insert into publisher values (null,#{pubName},#{contacter},#{mobile});")
    int insertPublisher(Publisher publisher);

    @Update({"<script>update publisher" ,
            "        <set>" ,
            "            <if test=\"pubName!=null and pubName!=''\">" ,
            "                pub_name=#{pubName}," ,
            "            </if>" ,
            "            <if test=\"contacter!=null and contacter!=''\">" ,
            "                contacter=#{contacter}," ,
            "            </if>" ,
            "            <if test=\"mobile!=null and mobile!=''\">\n" ,
            "                mobile=#{mobile}," ,
            "            </if>" ,
            "        </set>" ,
            "        where pub_id=#{pubId}</script>"})
    int updatePublisher(Publisher publisher);

    @Delete("delete from publisher where pub_id=#{pubId};")
    int deletePublisher(int pubId);

    @Select("select * from publisher where pub_id=#{pubId};")
    @Results({@Result(id = true,column = "pub_id",property = "pubId"),
            @Result(property = "bookList",column = "pub_id",many =
            @Many(select = "com.my.mybits.mapper.BookMapper.findBookByPubId"))})
    Publisher findPublisherByColPubId(int pubId);
    /* <insert id="insertPublisher" parameterType="Publisher" keyColumn="pub_id" keyProperty="pubId" useGeneratedKeys="true">
    insert into publisher values (#{pubId},#{pubName},#{contacter},#{mobile});
    </insert>  */

    /*<update id="updatePublisher" parameterType="Publisher" >
        update publisher
        <set>
            <if test="pubName!=null and pubName!=''">
                pub_name=#{pubName},
            </if>
            <if test="contacter!=null and contacter!=''">
                contacter=#{contacter},
            </if>
            <if test="mobile!=null and mobile!=''">
                mobile=#{mobile},
            </if>
        </set>
        where pub_id=#{pubId}
    </update>  */
}
